package com.singleton.type8;

//使用枚举可以实现单例模式
enum Singleton {
    INSTANCE;

    public void sayOK() {
        System.out.println("ok~");
    }
}

/**
 * @author 薛虎
 * @date 2020/12/16 11:14
 * 使用枚举可以实现单例模式
 */
public class SingletonTest08 {

    public static void main(String[] args) {
        Singleton singleton = Singleton.INSTANCE;
        Singleton singleton1 = Singleton.INSTANCE;

        System.out.println(singleton == singleton1);

        System.out.println(singleton.hashCode());
        System.out.println(singleton1.hashCode());

        singleton.sayOK();
    }


}